// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso.sprite;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Stack;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import zombie.characters.IsoPlayer;
import zombie.core.Core;
import zombie.core.SpriteRenderer;
import zombie.core.opengl.CharacterModelCamera;
import zombie.core.properties.PropertyContainer;
import zombie.core.skinnedmodel.ModelCameraRenderData;
import zombie.core.skinnedmodel.ModelManager;
import zombie.core.textures.ColorInfo;
import zombie.core.textures.Mask;
import zombie.core.textures.Texture;
import zombie.core.textures.TextureDraw;
import zombie.debug.DebugOptions;
import zombie.debug.LineDrawer;
import zombie.iso.IsoCamera;
import zombie.iso.IsoDirections;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMovingObject;
import zombie.iso.IsoObject;
import zombie.iso.IsoObjectPicker;
import zombie.iso.IsoUtils;
import zombie.iso.IsoWater;
import zombie.iso.Vector2;
import zombie.iso.Vector3;
import zombie.iso.WorldConverter;
import zombie.iso.SpriteDetails.IsoObjectType;
import zombie.util.StringUtils;
import zombie.vehicles.BaseVehicle;
import zombie.vehicles.VehicleModelCamera;

public final class IsoSprite {
    public static int maxCount = 0;
    public static float alphaStep = 0.05F;
    public static float globalOffsetX = -1.0F;
    public static float globalOffsetY = -1.0F;
    private static final ColorInfo info = new ColorInfo();
    private static final HashMap<String, Object[]> AnimNameSet = new HashMap();
    public int firerequirement;
    public String burntTile;
    public boolean forceAmbient;
    public boolean solidfloor;
    public boolean canBeRemoved;
    public boolean attachedFloor;
    public boolean cutW;
    public boolean cutN;
    public boolean solid;
    public boolean solidTrans;
    public boolean invisible;
    public boolean alwaysDraw;
    public boolean forceRender;
    public boolean moveWithWind = false;
    public boolean isBush = false;
    public static final byte RL_DEFAULT = 0;
    public static final byte RL_FLOOR = 1;
    public byte renderLayer = 0;
    public int windType = 1;
    public boolean Animate = true;
    public IsoAnim CurrentAnim = null;
    public boolean DeleteWhenFinished = false;
    public boolean Loop = true;
    public short soffX = 0;
    public short soffY = 0;
    public final PropertyContainer Properties = new PropertyContainer();
    public final ColorInfo TintMod = new ColorInfo(1.0F, 1.0F, 1.0F, 1.0F);
    public final HashMap<String, IsoAnim> AnimMap = new HashMap(2);
    public final ArrayList<IsoAnim> AnimStack = new ArrayList(1);
    public String name;
    public int tileSheetIndex = 0;
    public int ID = 20000000;
    public IsoSpriteInstance def;
    public ModelManager.ModelSlot modelSlot;
    IsoSpriteManager parentManager;
    private IsoObjectType type = IsoObjectType.MAX;
    private String parentObjectName = null;
    private IsoSpriteGrid spriteGrid;
    public boolean treatAsWallOrder = false;
    private boolean hideForWaterRender = false;

    public void setHideForWaterRender() {
        this.hideForWaterRender = true;
    }

    public IsoSprite() {
        this.parentManager = IsoSpriteManager.instance;
        this.def = IsoSpriteInstance.get(this);
    }

    public IsoSprite(IsoSpriteManager manager) {
        this.parentManager = manager;
        this.def = IsoSpriteInstance.get(this);
    }

    public static IsoSprite CreateSprite(IsoSpriteManager manager) {
        return new IsoSprite(manager);
    }

    public static IsoSprite CreateSpriteUsingCache(String objectName, String animName, int numFrames) {
        IsoSprite isoSprite = CreateSprite(IsoSpriteManager.instance);
        return isoSprite.setFromCache(objectName, animName, numFrames);
    }

    public static IsoSprite getSprite(IsoSpriteManager manager, int id) {
        if (WorldConverter.instance.TilesetConversions != null
            && !WorldConverter.instance.TilesetConversions.isEmpty()
            && WorldConverter.instance.TilesetConversions.containsKey(id)) {
            id = (Integer)WorldConverter.instance.TilesetConversions.get(id);
        }

        return manager.IntMap.containsKey(id) ? manager.IntMap.get(id) : null;
    }

    public static void setSpriteID(IsoSpriteManager manager, int id, IsoSprite spr) {
        if (manager.IntMap.containsKey(spr.ID)) {
            manager.IntMap.remove(spr.ID);
            spr.ID = id;
            manager.IntMap.put(id, spr);
        }
    }

    public static IsoSprite getSprite(IsoSpriteManager manager, IsoSprite spr, int offset) {
        if (spr.name.contains("_")) {
            String[] string = spr.name.split("_");
            int _int = Integer.parseInt(string[string.length - 1].trim());
            _int += offset;
            return (IsoSprite)manager.NamedMap.get(spr.name.substring(0, spr.name.lastIndexOf("_")) + "_" + _int);
        } else {
            return null;
        }
    }

    public static IsoSprite getSprite(IsoSpriteManager manager, String _name, int offset) {
        IsoSprite isoSprite = (IsoSprite)manager.NamedMap.get(_name);
        String string0 = isoSprite.name.substring(0, isoSprite.name.lastIndexOf(95));
        String string1 = isoSprite.name.substring(isoSprite.name.lastIndexOf(95) + 1);
        if (isoSprite.name.contains("_")) {
            int _int = Integer.parseInt(string1.trim());
            _int += offset;
            return manager.getSprite(string0 + "_" + _int);
        } else {
            return null;
        }
    }

    public static void DisposeAll() {
        AnimNameSet.clear();
    }

    public static boolean HasCache(String string) {
        return AnimNameSet.containsKey(string);
    }

    public IsoSpriteInstance newInstance() {
        return IsoSpriteInstance.get(this);
    }

    public PropertyContainer getProperties() {
        return this.Properties;
    }

    public String getParentObjectName() {
        return this.parentObjectName;
    }

    public void setParentObjectName(String val) {
        this.parentObjectName = val;
    }

    public void save(DataOutputStream output) throws IOException {
        zombie.GameWindow.WriteString(output, this.name);
    }

    public void load(DataInputStream input) throws IOException {
        this.name = zombie.GameWindow.ReadString(input);
        this.LoadFramesNoDirPageSimple(this.name);
    }

    public void Dispose() {
        for (IsoAnim isoAnim : this.AnimMap.values()) {
            isoAnim.Dispose();
        }

        this.AnimMap.clear();
        this.AnimStack.clear();
        this.CurrentAnim = null;
    }

    public boolean isMaskClicked(IsoDirections dir, int x, int y) {
        try {
            Texture texture = ((IsoDirectionFrame)this.CurrentAnim.Frames.get((int)this.def.Frame)).directions[dir.index()];
            if (texture == null) {
                return false;
            } else {
                Mask mask = texture.getMask();
                if (mask == null) {
                    return false;
                } else {
                    x = (int)((float)x - texture.offsetX);
                    y = (int)((float)y - texture.offsetY);
                    return mask.get(x, y);
                }
            }
        } catch (Exception exception) {
            Logger.getLogger(zombie.GameWindow.class.getName()).log(Level.SEVERE, null, exception);
            return true;
        }
    }

    public boolean isMaskClicked(IsoDirections dir, int x, int y, boolean flip) {
        if (this.CurrentAnim == null) {
            return false;
        } else {
            this.initSpriteInstance();

            try {
                if (this.CurrentAnim != null && this.CurrentAnim.Frames != null && !(this.def.Frame >= (float)this.CurrentAnim.Frames.size())) {
                    Texture texture = ((IsoDirectionFrame)this.CurrentAnim.Frames.get((int)this.def.Frame)).directions[dir.index()];
                    if (texture == null) {
                        return false;
                    } else {
                        Mask mask = texture.getMask();
                        if (mask == null) {
                            return false;
                        } else {
                            if (flip) {
                                x = (int)((float)x - ((float)(texture.getWidthOrig() - texture.getWidth()) - texture.offsetX));
                                y = (int)((float)y - texture.offsetY);
                                x = texture.getWidth() - x;
                            } else {
                                x = (int)((float)x - texture.offsetX);
                                y = (int)((float)y - texture.offsetY);
                            }

                            return x >= 0 && y >= 0 && x <= texture.getWidth() && y <= texture.getHeight() ? mask.get(x, y) : false;
                        }
                    }
                } else {
                    return false;
                }
            } catch (Exception exception) {
                Logger.getLogger(zombie.GameWindow.class.getName()).log(Level.SEVERE, null, exception);
                return true;
            }
        }
    }

    public float getMaskClickedY(IsoDirections dir, int x, int y, boolean flip) {
        try {
            Texture texture = ((IsoDirectionFrame)this.CurrentAnim.Frames.get((int)this.def.Frame)).directions[dir.index()];
            if (texture == null) {
                return 10000.0F;
            } else {
                Mask mask = texture.getMask();
                if (mask == null) {
                    return 10000.0F;
                } else {
                    if (flip) {
                        x = (int)((float)x - ((float)(texture.getWidthOrig() - texture.getWidth()) - texture.offsetX));
                        y = (int)((float)y - texture.offsetY);
                        x = texture.getWidth() - x;
                    } else {
                        x = (int)((float)x - texture.offsetX);
                        y = (int)((float)y - texture.offsetY);
                        x = texture.getWidth() - x;
                    }

                    return (float)y;
                }
            }
        } catch (Exception exception) {
            Logger.getLogger(zombie.GameWindow.class.getName()).log(Level.SEVERE, null, exception);
            return 10000.0F;
        }
    }

    public Texture LoadFrameExplicit(String ObjectName) {
        this.CurrentAnim = new IsoAnim();
        this.AnimMap.put("default", this.CurrentAnim);
        this.CurrentAnim.ID = this.AnimStack.size();
        this.AnimStack.add(this.CurrentAnim);
        return this.CurrentAnim.LoadFrameExplicit(ObjectName);
    }

    public void LoadFrames(String ObjectName, String AnimName, int nFrames) {
        if (!this.AnimMap.containsKey(AnimName)) {
            this.CurrentAnim = new IsoAnim();
            this.AnimMap.put(AnimName, this.CurrentAnim);
            this.CurrentAnim.ID = this.AnimStack.size();
            this.AnimStack.add(this.CurrentAnim);
            this.CurrentAnim.LoadFrames(ObjectName, AnimName, nFrames);
        }
    }

    public void LoadFramesReverseAltName(String ObjectName, String AnimName, String AltName, int nFrames) {
        if (!this.AnimMap.containsKey(AltName)) {
            this.CurrentAnim = new IsoAnim();
            this.AnimMap.put(AltName, this.CurrentAnim);
            this.CurrentAnim.ID = this.AnimStack.size();
            this.AnimStack.add(this.CurrentAnim);
            this.CurrentAnim.LoadFramesReverseAltName(ObjectName, AnimName, AltName, nFrames);
        }
    }

    public void LoadFramesNoDirPage(String ObjectName, String AnimName, int nFrames) {
        this.CurrentAnim = new IsoAnim();
        this.AnimMap.put(AnimName, this.CurrentAnim);
        this.CurrentAnim.ID = this.AnimStack.size();
        this.AnimStack.add(this.CurrentAnim);
        this.CurrentAnim.LoadFramesNoDirPage(ObjectName, AnimName, nFrames);
    }

    public void LoadFramesNoDirPageDirect(String ObjectName, String AnimName, int nFrames) {
        this.CurrentAnim = new IsoAnim();
        this.AnimMap.put(AnimName, this.CurrentAnim);
        this.CurrentAnim.ID = this.AnimStack.size();
        this.AnimStack.add(this.CurrentAnim);
        this.CurrentAnim.LoadFramesNoDirPageDirect(ObjectName, AnimName, nFrames);
    }

    public void LoadFramesNoDirPageSimple(String ObjectName) {
        if (this.AnimMap.containsKey("default")) {
            IsoAnim isoAnim = (IsoAnim)this.AnimMap.get("default");
            this.AnimStack.remove(isoAnim);
            this.AnimMap.remove("default");
        }

        this.CurrentAnim = new IsoAnim();
        this.AnimMap.put("default", this.CurrentAnim);
        this.CurrentAnim.ID = this.AnimStack.size();
        this.AnimStack.add(this.CurrentAnim);
        this.CurrentAnim.LoadFramesNoDirPage(ObjectName);
    }

    public void ReplaceCurrentAnimFrames(String ObjectName) {
        if (this.CurrentAnim != null) {
            this.CurrentAnim.Frames.clear();
            this.CurrentAnim.LoadFramesNoDirPage(ObjectName);
        }
    }

    public void LoadFramesPageSimple(String NObjectName, String SObjectName, String EObjectName, String WObjectName) {
        this.CurrentAnim = new IsoAnim();
        this.AnimMap.put("default", this.CurrentAnim);
        this.CurrentAnim.ID = this.AnimStack.size();
        this.AnimStack.add(this.CurrentAnim);
        this.CurrentAnim.LoadFramesPageSimple(NObjectName, SObjectName, EObjectName, WObjectName);
    }

    public void LoadFramesPcx(String ObjectName, String AnimName, int nFrames) {
        if (!this.AnimMap.containsKey(AnimName)) {
            this.CurrentAnim = new IsoAnim();
            this.AnimMap.put(AnimName, this.CurrentAnim);
            this.CurrentAnim.ID = this.AnimStack.size();
            this.AnimStack.add(this.CurrentAnim);
            this.CurrentAnim.LoadFramesPcx(ObjectName, AnimName, nFrames);
        }
    }

    public void PlayAnim(IsoAnim anim) {
        if (this.CurrentAnim == null || this.CurrentAnim != anim) {
            this.CurrentAnim = anim;
        }
    }

    public void PlayAnim(String _name) {
        if ((this.CurrentAnim == null || !this.CurrentAnim.name.equals(_name)) && this.AnimMap.containsKey(_name)) {
            this.CurrentAnim = (IsoAnim)this.AnimMap.get(_name);
        }
    }

    public void PlayAnimUnlooped(String _name) {
        if (this.AnimMap.containsKey(_name)) {
            if (this.CurrentAnim == null || !this.CurrentAnim.name.equals(_name)) {
                this.CurrentAnim = (IsoAnim)this.AnimMap.get(_name);
            }

            this.CurrentAnim.looped = false;
        }
    }

    public void ChangeTintMod(ColorInfo NewTintMod) {
        this.TintMod.r = NewTintMod.r;
        this.TintMod.g = NewTintMod.g;
        this.TintMod.b = NewTintMod.b;
        this.TintMod.a = NewTintMod.a;
    }

    public void RenderGhostTile(int x, int y, int z) {
        IsoSpriteInstance isoSpriteInstance = IsoSpriteInstance.get(this);
        isoSpriteInstance.alpha = isoSpriteInstance.targetAlpha = 0.6F;
        this.render(
            isoSpriteInstance,
            null,
            (float)x,
            (float)y,
            (float)z,
            IsoDirections.N,
            (float)(32 * Core.TileScale),
            (float)(96 * Core.TileScale),
            IsoGridSquare.getDefColorInfo(),
            true
        );
    }

    public void RenderGhostTileRed(int x, int y, int z) {
        IsoSpriteInstance isoSpriteInstance = IsoSpriteInstance.get(this);
        isoSpriteInstance.tintr = 0.65F;
        isoSpriteInstance.tintg = 0.2F;
        isoSpriteInstance.tintb = 0.2F;
        isoSpriteInstance.alpha = isoSpriteInstance.targetAlpha = 0.6F;
        this.render(
            isoSpriteInstance,
            null,
            (float)x,
            (float)y,
            (float)z,
            IsoDirections.N,
            (float)(32 * Core.TileScale),
            (float)(96 * Core.TileScale),
            IsoGridSquare.getDefColorInfo(),
            true
        );
    }

    public void RenderGhostTileColor(int x, int y, int z, float r, float g, float b, float a) {
        this.RenderGhostTileColor(x, y, z, 0.0F, 0.0F, r, g, b, a);
    }

    public void RenderGhostTileColor(int x, int y, int z, float offsetX, float offsetY, float r, float g, float b, float a) {
        IsoSpriteInstance isoSpriteInstance = IsoSpriteInstance.get(this);
        isoSpriteInstance.tintr = r;
        isoSpriteInstance.tintg = g;
        isoSpriteInstance.tintb = b;
        isoSpriteInstance.alpha = isoSpriteInstance.targetAlpha = a;
        IsoGridSquare.getDefColorInfo().r = IsoGridSquare.getDefColorInfo().g = IsoGridSquare.getDefColorInfo().b = IsoGridSquare.getDefColorInfo().a = 1.0F;
        int _int = Core.TileScale;
        this.render(
            isoSpriteInstance,
            null,
            (float)x,
            (float)y,
            (float)z,
            IsoDirections.N,
            (float)(32 * _int) + offsetX,
            (float)(96 * _int) + offsetY,
            IsoGridSquare.getDefColorInfo(),
            true
        );
    }

    public boolean hasActiveModel() {
        if (!ModelManager.instance.bDebugEnableModels) {
            return false;
        } else {
            return !ModelManager.instance.isCreated() ? false : this.modelSlot != null && this.modelSlot.active;
        }
    }

    public void renderVehicle(
        IsoSpriteInstance inst, IsoObject obj, float x, float y, float z, float offsetX, float offsetY, ColorInfo info2, boolean bDoRenderPrep
    ) {
        if (inst != null) {
            if (this.hasActiveModel()) {
                SpriteRenderer.instance.drawGeneric(ModelCameraRenderData.s_pool.alloc().init(VehicleModelCamera.instance, this.modelSlot));
                SpriteRenderer.instance.drawModel(this.modelSlot);
                if (!BaseVehicle.RENDER_TO_TEXTURE) {
                    return;
                }
            }

            info.r = info2.r;
            info.g = info2.g;
            info.b = info2.b;
            info.a = info2.a;

            try {
                if (bDoRenderPrep) {
                    inst.renderprep(obj);
                }

                float float0 = 0.0F;
                float float1 = 0.0F;
                if (globalOffsetX == -1.0F) {
                    globalOffsetX = -IsoCamera.frameState.OffX;
                    globalOffsetY = -IsoCamera.frameState.OffY;
                }

                if (obj == null || obj.sx == 0.0F || obj instanceof IsoMovingObject) {
                    float0 = IsoUtils.XToScreen(x + inst.offX, y + inst.offY, z + inst.offZ, 0);
                    float1 = IsoUtils.YToScreen(x + inst.offX, y + inst.offY, z + inst.offZ, 0);
                    float0 -= offsetX;
                    float1 -= offsetY;
                    if (obj != null) {
                        obj.sx = float0;
                        obj.sy = float1;
                    }
                }

                if (obj != null) {
                    float0 = obj.sx + globalOffsetX;
                    float1 = obj.sy + globalOffsetY;
                    float0 += (float)this.soffX;
                    float1 += (float)this.soffY;
                } else {
                    float0 += globalOffsetX;
                    float1 += globalOffsetY;
                    float0 += (float)this.soffX;
                    float1 += (float)this.soffY;
                }

                if (bDoRenderPrep) {
                    if (inst.tintr != 1.0F || inst.tintg != 1.0F || inst.tintb != 1.0F) {
                        info.r = info.r * inst.tintr;
                        info.g = info.g * inst.tintg;
                        info.b = info.b * inst.tintb;
                    }

                    info.a = inst.alpha;
                }

                if (!this.hasActiveModel() && (this.TintMod.r != 1.0F || this.TintMod.g != 1.0F || this.TintMod.b != 1.0F)) {
                    info.r = info.r * this.TintMod.r;
                    info.g = info.g * this.TintMod.g;
                    info.b = info.b * this.TintMod.b;
                }

                if (this.hasActiveModel()) {
                    float float2 = inst.getScaleX() * (float)Core.TileScale;
                    float float3 = -inst.getScaleY() * (float)Core.TileScale;
                    float float4 = 0.666F;
                    float2 /= 4.0F * float4;
                    float3 /= 4.0F * float4;
                    int int0 = ModelManager.instance.bitmap.getTexture().getWidth();
                    int int1 = ModelManager.instance.bitmap.getTexture().getHeight();
                    float0 -= (float)int0 * float2 / 2.0F;
                    float1 -= (float)int1 * float3 / 2.0F;
                    float float5 = ((BaseVehicle)obj).jniTransform.origin.y / 2.46F;
                    float1 += 96.0F * float5 / float3 / float4;
                    float1 += 27.84F / float3 / float4;
                    if (Core.getInstance().RenderShader != null && Core.getInstance().getOffscreenBuffer() != null) {
                        SpriteRenderer.instance
                            .render(
                                (Texture)ModelManager.instance.bitmap.getTexture(),
                                float0,
                                float1,
                                (float)int0 * float2,
                                (float)int1 * float3,
                                1.0F,
                                1.0F,
                                1.0F,
                                info.a,
                                null
                            );
                    } else {
                        SpriteRenderer.instance
                            .render(
                                (Texture)ModelManager.instance.bitmap.getTexture(),
                                float0,
                                float1,
                                (float)int0 * float2,
                                (float)int1 * float3,
                                info.r,
                                info.g,
                                info.b,
                                info.a,
                                null
                            );
                    }

                    if (Core.bDebug && DebugOptions.instance.ModelRenderBounds.getValue()) {
                        LineDrawer.drawRect(float0, float1, (float)int0 * float2, (float)int1 * float3, 1.0F, 1.0F, 1.0F, 1.0F, 1);
                    }
                }

                info.r = 1.0F;
                info.g = 1.0F;
                info.b = 1.0F;
            } catch (Exception exception) {
                Logger.getLogger(zombie.GameWindow.class.getName()).log(Level.SEVERE, null, exception);
            }
        }
    }

    private IsoSpriteInstance getSpriteInstance() {
        this.initSpriteInstance();
        return this.def;
    }

    private void initSpriteInstance() {
        if (this.def == null) {
            this.def = IsoSpriteInstance.get(this);
        }
    }

    public final void render(IsoObject obj, float x, float y, float z, IsoDirections dir, float offsetX, float offsetY, ColorInfo info2, boolean bDoRenderPrep) {
        this.render(obj, x, y, z, dir, offsetX, offsetY, info2, bDoRenderPrep, null);
    }

    public final void render(
        IsoObject obj,
        float x,
        float y,
        float z,
        IsoDirections dir,
        float offsetX,
        float offsetY,
        ColorInfo info2,
        boolean bDoRenderPrep,
        Consumer<TextureDraw> texdModifier
    ) {
        this.render(this.getSpriteInstance(), obj, x, y, z, dir, offsetX, offsetY, info2, bDoRenderPrep, texdModifier);
    }

    public final void render(
        IsoSpriteInstance inst,
        IsoObject obj,
        float x,
        float y,
        float z,
        IsoDirections dir,
        float offsetX,
        float offsetY,
        ColorInfo info2,
        boolean bDoRenderPrep
    ) {
        this.render(inst, obj, x, y, z, dir, offsetX, offsetY, info2, bDoRenderPrep, null);
    }

    public void render(
        IsoSpriteInstance inst,
        IsoObject obj,
        float x,
        float y,
        float z,
        IsoDirections dir,
        float offsetX,
        float offsetY,
        ColorInfo info2,
        boolean bDoRenderPrep,
        Consumer<TextureDraw> texdModifier
    ) {
        if (this.hasActiveModel()) {
            this.renderActiveModel();
        } else {
            this.renderCurrentAnim(inst, obj, x, y, z, dir, offsetX, offsetY, info2, bDoRenderPrep, texdModifier);
        }
    }

    public void renderCurrentAnim(
        IsoSpriteInstance inst,
        IsoObject obj,
        float x,
        float y,
        float z,
        IsoDirections dir,
        float offsetX,
        float offsetY,
        ColorInfo col,
        boolean bDoRenderPrep,
        Consumer<TextureDraw> texdModifier
    ) {
        if (DebugOptions.instance.IsoSprite.RenderSprites.getValue()) {
            if (this.CurrentAnim != null && !this.CurrentAnim.Frames.isEmpty()) {
                float _float = this.getCurrentSpriteFrame(inst);
                info.set(col);
                Vector3 vector3 = IsoSprite.l_renderCurrentAnim.colorInfoBackup.set(info.r, info.g, info.b);
                Vector2 vector2 = IsoSprite.l_renderCurrentAnim.spritePos.set(0.0F, 0.0F);
                this.prepareToRenderSprite(inst, obj, x, y, z, dir, offsetX, offsetY, bDoRenderPrep, (int)_float, vector2);
                this.performRenderFrame(inst, obj, dir, (int)_float, vector2.x, vector2.y, texdModifier);
                info.r = vector3.x;
                info.g = vector3.y;
                info.b = vector3.z;
            }
        }
    }

    private float getCurrentSpriteFrame(IsoSpriteInstance isoSpriteInstance) {
        if (this.CurrentAnim.FramesArray == null) {
            this.CurrentAnim.FramesArray = (IsoDirectionFrame[])this.CurrentAnim.Frames.toArray(new IsoDirectionFrame[0]);
        }

        if (this.CurrentAnim.FramesArray.length != this.CurrentAnim.Frames.size()) {
            this.CurrentAnim.FramesArray = (IsoDirectionFrame[])this.CurrentAnim.Frames.toArray(this.CurrentAnim.FramesArray);
        }

        float _float;
        if (isoSpriteInstance.Frame >= (float)this.CurrentAnim.Frames.size()) {
            _float = (float)(this.CurrentAnim.FramesArray.length - 1);
        } else if (isoSpriteInstance.Frame < 0.0F) {
            isoSpriteInstance.Frame = 0.0F;
            _float = 0.0F;
        } else {
            _float = isoSpriteInstance.Frame;
        }

        return _float;
    }

    private void prepareToRenderSprite(
        IsoSpriteInstance isoSpriteInstance,
        IsoObject isoObject,
        float float4,
        float float3,
        float float2,
        IsoDirections isoDirections,
        float float5,
        float float6,
        boolean _boolean,
        int _int,
        Vector2 vector2
    ) {
        if (_boolean) {
            isoSpriteInstance.renderprep(isoObject);
        }

        float float0 = 0.0F;
        float float1 = 0.0F;
        if (globalOffsetX == -1.0F) {
            globalOffsetX = -IsoCamera.frameState.OffX;
            globalOffsetY = -IsoCamera.frameState.OffY;
        }

        if (isoObject == null || isoObject.sx == 0.0F || isoObject instanceof IsoMovingObject) {
            float0 = IsoUtils.XToScreen(float4 + isoSpriteInstance.offX, float3 + isoSpriteInstance.offY, float2 + isoSpriteInstance.offZ, 0);
            float1 = IsoUtils.YToScreen(float4 + isoSpriteInstance.offX, float3 + isoSpriteInstance.offY, float2 + isoSpriteInstance.offZ, 0);
            float0 -= float5;
            float1 -= float6;
            if (isoObject != null) {
                isoObject.sx = float0;
                isoObject.sy = float1;
            }

            float0 += globalOffsetX;
            float1 += globalOffsetY;
            float0 += (float)this.soffX;
            float1 += (float)this.soffY;
        } else if (isoObject != null) {
            float0 = isoObject.sx + globalOffsetX;
            float1 = isoObject.sy + globalOffsetY;
            float0 += (float)this.soffX;
            float1 += (float)this.soffY;
        } else {
            float0 += globalOffsetX;
            float1 += globalOffsetY;
            float0 += (float)this.soffX;
            float1 += (float)this.soffY;
        }

        if (isoObject instanceof IsoMovingObject && this.CurrentAnim != null && this.CurrentAnim.FramesArray[_int].getTexture(isoDirections) != null) {
            float0 -= (float)(this.CurrentAnim.FramesArray[_int].getTexture(isoDirections).getWidthOrig() / 2) * isoSpriteInstance.getScaleX();
            float1 -= (float)this.CurrentAnim.FramesArray[_int].getTexture(isoDirections).getHeightOrig() * isoSpriteInstance.getScaleY();
        }

        if (_boolean) {
            if (isoSpriteInstance.tintr != 1.0F || isoSpriteInstance.tintg != 1.0F || isoSpriteInstance.tintb != 1.0F) {
                info.r = info.r * isoSpriteInstance.tintr;
                info.g = info.g * isoSpriteInstance.tintg;
                info.b = info.b * isoSpriteInstance.tintb;
            }

            info.a = isoSpriteInstance.alpha;
            if (isoSpriteInstance.bMultiplyObjectAlpha && isoObject != null) {
                info.a = info.a * isoObject.getAlpha(IsoCamera.frameState.playerIndex);
            }
        }

        if (this.TintMod.r != 1.0F || this.TintMod.g != 1.0F || this.TintMod.b != 1.0F) {
            info.r = info.r * this.TintMod.r;
            info.g = info.g * this.TintMod.g;
            info.b = info.b * this.TintMod.b;
        }

        vector2.set(float0, float1);
    }

    private void performRenderFrame(
        IsoSpriteInstance isoSpriteInstance,
        IsoObject isoObject,
        IsoDirections isoDirections,
        int _int,
        float float4,
        float float5,
        Consumer<TextureDraw> consumer
    ) {
        if (_int < this.CurrentAnim.FramesArray.length) {
            IsoDirectionFrame isoDirectionFrame = this.CurrentAnim.FramesArray[_int];
            Texture texture = isoDirectionFrame.getTexture(isoDirections);
            if (texture != null) {
                if (Core.TileScale == 2 && texture.getWidthOrig() == 64 && texture.getHeightOrig() == 128) {
                    isoSpriteInstance.setScale(2.0F, 2.0F);
                }

                if (Core.TileScale == 2
                    && isoSpriteInstance.scaleX == 2.0F
                    && isoSpriteInstance.scaleY == 2.0F
                    && texture.getWidthOrig() == 128
                    && texture.getHeightOrig() == 256) {
                    isoSpriteInstance.setScale(1.0F, 1.0F);
                }

                if (!(isoSpriteInstance.scaleX <= 0.0F) && !(isoSpriteInstance.scaleY <= 0.0F)) {
                    float float0 = (float)texture.getWidth();
                    float float1 = (float)texture.getHeight();
                    float float2 = isoSpriteInstance.scaleX;
                    float float3 = isoSpriteInstance.scaleY;
                    if (float2 != 1.0F) {
                        float4 += texture.getOffsetX() * (float2 - 1.0F);
                        float0 *= float2;
                    }

                    if (float3 != 1.0F) {
                        float5 += texture.getOffsetY() * (float3 - 1.0F);
                        float1 *= float3;
                    }

                    if (DebugOptions.instance.IsoSprite.MovingObjectEdges.getValue() && isoObject instanceof IsoMovingObject) {
                        this.renderSpriteOutline(float4, float5, texture, float2, float3);
                    }

                    if (DebugOptions.instance.IsoSprite.DropShadowEdges.getValue() && StringUtils.equals(texture.getName(), "dropshadow")) {
                        this.renderSpriteOutline(float4, float5, texture, float2, float3);
                    }

                    if (!this.hideForWaterRender || !IsoWater.getInstance().getShaderEnable()) {
                        if (isoObject != null && isoObject.getObjectRenderEffectsToApply() != null) {
                            isoDirectionFrame.render(
                                isoObject.getObjectRenderEffectsToApply(),
                                float4,
                                float5,
                                float0,
                                float1,
                                isoDirections,
                                info,
                                isoSpriteInstance.Flip,
                                consumer
                            );
                        } else {
                            isoDirectionFrame.render(float4, float5, float0, float1, isoDirections, info, isoSpriteInstance.Flip, consumer);
                        }
                    }

                    if (_int < this.CurrentAnim.FramesArray.length
                        && IsoObjectPicker.Instance.wasDirty
                        && IsoCamera.frameState.playerIndex == 0
                        && isoObject != null) {
                        boolean _boolean = isoDirections == IsoDirections.W || isoDirections == IsoDirections.SW || isoDirections == IsoDirections.S;
                        if (isoSpriteInstance.Flip) {
                            _boolean = !_boolean;
                        }

                        float4 = isoObject.sx + globalOffsetX;
                        float5 = isoObject.sy + globalOffsetY;
                        if (isoObject instanceof IsoMovingObject) {
                            float4 -= (float)(texture.getWidthOrig() / 2) * float2;
                            float5 -= (float)texture.getHeightOrig() * float3;
                        }

                        IsoObjectPicker.Instance
                            .Add(
                                (int)float4,
                                (int)float5,
                                (int)((float)texture.getWidthOrig() * float2),
                                (int)((float)texture.getHeightOrig() * float3),
                                isoObject.square,
                                isoObject,
                                _boolean,
                                float2,
                                float3
                            );
                    }
                }
            }
        }
    }

    private void renderSpriteOutline(float float0, float float1, Texture texture, float float3, float float2) {
        LineDrawer.drawRect(float0, float1, (float)texture.getWidthOrig() * float3, (float)texture.getHeightOrig() * float2, 1.0F, 1.0F, 1.0F, 1.0F, 1);
        LineDrawer.drawRect(
            float0 + texture.getOffsetX() * float3,
            float1 + texture.getOffsetY() * float2,
            (float)texture.getWidth() * float3,
            (float)texture.getHeight() * float2,
            1.0F,
            1.0F,
            1.0F,
            1.0F,
            1
        );
    }

    public void renderActiveModel() {
        if (DebugOptions.instance.IsoSprite.RenderModels.getValue()) {
            this.modelSlot.model.updateLights();
            SpriteRenderer.instance.drawGeneric(ModelCameraRenderData.s_pool.alloc().init(CharacterModelCamera.instance, this.modelSlot));
            SpriteRenderer.instance.drawModel(this.modelSlot);
        }
    }

    public void renderBloodSplat(float x, float y, float z, ColorInfo info2) {
        if (this.CurrentAnim != null && !this.CurrentAnim.Frames.isEmpty()) {
            byte byte0 = -8;
            short _short = -228;
            byte0 = 0;
            byte byte1 = 0;

            try {
                if (globalOffsetX == -1.0F) {
                    globalOffsetX = -IsoCamera.frameState.OffX;
                    globalOffsetY = -IsoCamera.frameState.OffY;
                }

                float float0 = IsoUtils.XToScreen(x, y, z, 0);
                float float1 = IsoUtils.YToScreen(x, y, z, 0);
                float0 = (float)((int)float0);
                float1 = (float)((int)float1);
                float0 -= (float)byte0;
                float1 -= (float)byte1;
                float0 += globalOffsetX;
                float1 += globalOffsetY;
                if (float0 >= (float)IsoCamera.frameState.OffscreenWidth || float0 + 64.0F <= 0.0F) {
                    return;
                }

                if (float1 >= (float)IsoCamera.frameState.OffscreenHeight || float1 + 64.0F <= 0.0F) {
                    return;
                }

                info.r = info2.r;
                info.g = info2.g;
                info.b = info2.b;
                info.a = info2.a;
                ((IsoDirectionFrame)this.CurrentAnim.Frames.get(0)).render(float0, float1, IsoDirections.N, info, false, null);
            } catch (Exception exception) {
                Logger.getLogger(zombie.GameWindow.class.getName()).log(Level.SEVERE, null, exception);
            }
        }
    }

    public void renderObjectPicker(IsoSpriteInstance _def, IsoObject obj, IsoDirections dir) {
        if (this.CurrentAnim != null) {
            if (_def != null) {
                if (IsoPlayer.getInstance() == IsoPlayer.players[0]) {
                    if (!this.CurrentAnim.Frames.isEmpty()) {
                        if (_def.Frame >= (float)this.CurrentAnim.Frames.size()) {
                            _def.Frame = 0.0F;
                        }

                        if (((IsoDirectionFrame)this.CurrentAnim.Frames.get((int)_def.Frame)).getTexture(dir) != null) {
                            float float0 = obj.sx + globalOffsetX;
                            float float1 = obj.sy + globalOffsetY;
                            if (obj instanceof IsoMovingObject) {
                                float0 -= (float)(((IsoDirectionFrame)this.CurrentAnim.Frames.get((int)_def.Frame)).getTexture(dir).getWidthOrig() / 2)
                                    * _def.getScaleX();
                                float1 -= (float)((IsoDirectionFrame)this.CurrentAnim.Frames.get((int)_def.Frame)).getTexture(dir).getHeightOrig()
                                    * _def.getScaleY();
                            }

                            if (_def.Frame < (float)this.CurrentAnim.Frames.size()
                                && IsoObjectPicker.Instance.wasDirty
                                && IsoCamera.frameState.playerIndex == 0) {
                                Texture texture = ((IsoDirectionFrame)this.CurrentAnim.Frames.get((int)_def.Frame)).getTexture(dir);
                                boolean _boolean = dir == IsoDirections.W || dir == IsoDirections.SW || dir == IsoDirections.S;
                                if (_def.Flip) {
                                    _boolean = !_boolean;
                                }

                                IsoObjectPicker.Instance
                                    .Add(
                                        (int)float0,
                                        (int)float1,
                                        (int)((float)texture.getWidthOrig() * _def.getScaleX()),
                                        (int)((float)texture.getHeightOrig() * _def.getScaleY()),
                                        obj.square,
                                        obj,
                                        _boolean,
                                        _def.getScaleX(),
                                        _def.getScaleY()
                                    );
                            }
                        }
                    }
                }
            }
        }
    }

    public Texture getTextureForFrame(int frame, IsoDirections dir) {
        if (this.CurrentAnim != null && !this.CurrentAnim.Frames.isEmpty()) {
            if (this.CurrentAnim.FramesArray == null) {
                this.CurrentAnim.FramesArray = (IsoDirectionFrame[])this.CurrentAnim.Frames.toArray(new IsoDirectionFrame[0]);
            }

            if (this.CurrentAnim.FramesArray.length != this.CurrentAnim.Frames.size()) {
                this.CurrentAnim.FramesArray = (IsoDirectionFrame[])this.CurrentAnim.Frames.toArray(this.CurrentAnim.FramesArray);
            }

            if (frame >= this.CurrentAnim.FramesArray.length) {
                frame = this.CurrentAnim.FramesArray.length - 1;
            }

            if (frame < 0) {
                frame = 0;
            }

            return this.CurrentAnim.FramesArray[frame].getTexture(dir);
        } else {
            return null;
        }
    }

    public Texture getTextureForCurrentFrame(IsoDirections dir) {
        this.initSpriteInstance();
        return this.getTextureForFrame((int)this.def.Frame, dir);
    }

    public void update() {
        this.update(this.def);
    }

    public void update(IsoSpriteInstance _def) {
        if (_def == null) {
            _def = IsoSpriteInstance.get(this);
        }

        if (this.CurrentAnim != null) {
            if (this.Animate && !_def.Finished) {
                float _float = _def.Frame;
                if (!zombie.GameTime.isGamePaused()) {
                    _def.Frame = _def.Frame + _def.AnimFrameIncrease * zombie.GameTime.instance.getMultipliedSecondsSinceLastUpdate() * 60.0F;
                }

                if ((int)_def.Frame >= this.CurrentAnim.Frames.size() && this.Loop && _def.Looped) {
                    _def.Frame = 0.0F;
                }

                if ((int)_float != (int)_def.Frame) {
                    _def.NextFrame = true;
                }

                if ((int)_def.Frame >= this.CurrentAnim.Frames.size() && (!this.Loop || !_def.Looped)) {
                    _def.Finished = true;
                    _def.Frame = (float)this.CurrentAnim.FinishUnloopedOnFrame;
                    if (this.DeleteWhenFinished) {
                        this.Dispose();
                        this.Animate = false;
                    }
                }
            }
        }
    }

    public void CacheAnims(String key) {
        this.name = key;
        Stack stack = new Stack();

        for (int _int = 0; _int < this.AnimStack.size(); _int++) {
            IsoAnim isoAnim = (IsoAnim)this.AnimStack.get(_int);
            String string = key + isoAnim.name;
            stack.add(string);
            if (!IsoAnim.GlobalAnimMap.containsKey(string)) {
                IsoAnim.GlobalAnimMap.put(string, isoAnim);
            }
        }

        AnimNameSet.put(key, stack.toArray());
    }

    public void LoadCache(String string) {
        Object[] object = (Object[])AnimNameSet.get(string);
        this.name = string;

        for (int _int = 0; _int < object.length; _int++) {
            String _string = (String)object[_int];
            IsoAnim isoAnim = (IsoAnim)IsoAnim.GlobalAnimMap.get(_string);
            this.AnimMap.put(isoAnim.name, isoAnim);
            this.AnimStack.add(isoAnim);
            this.CurrentAnim = isoAnim;
        }
    }

    public IsoSprite setFromCache(String objectName, String animName, int numFrames) {
        String string = objectName + animName;
        if (HasCache(string)) {
            this.LoadCache(string);
        } else {
            this.LoadFramesNoDirPage(objectName, animName, numFrames);
            this.CacheAnims(string);
        }

        return this;
    }

    public IsoObjectType getType() {
        return this.type;
    }

    public void setType(IsoObjectType ntype) {
        this.type = ntype;
    }

    public void AddProperties(IsoSprite sprite) {
        this.getProperties().AddProperties(sprite.getProperties());
    }

    public int getID() {
        return this.ID;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String string) {
        this.name = string;
    }

    public ColorInfo getTintMod() {
        return this.TintMod;
    }

    public void setTintMod(ColorInfo _info) {
        this.TintMod.set(_info);
    }

    public void setAnimate(boolean animate) {
        this.Animate = animate;
    }

    public IsoSpriteGrid getSpriteGrid() {
        return this.spriteGrid;
    }

    public void setSpriteGrid(IsoSpriteGrid sGrid) {
        this.spriteGrid = sGrid;
    }

    public boolean isMoveWithWind() {
        return this.moveWithWind;
    }

    public int getSheetGridIdFromName() {
        return this.name != null ? getSheetGridIdFromName(this.name) : -1;
    }

    public static int getSheetGridIdFromName(String _name) {
        if (_name != null) {
            int _int = _name.lastIndexOf(95);
            if (_int > 0 && _int + 1 < _name.length()) {
                return Integer.parseInt(_name.substring(_int + 1));
            }
        }

        return -1;
    }

    private static class l_renderCurrentAnim {
        static final Vector3 colorInfoBackup = new Vector3();
        static final Vector2 spritePos = new Vector2();
    }
}
